package com.hy.study.driver;

import com.hy.study.mapper.FilterMapper;
import com.hy.study.outputfromat.FilterOutputFilter;
import com.hy.study.reduce.FilterReducer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

/**
 * @author huyong
 * @date 2024 年 02 月 06 日 10:41: 22
 */
public class FilterDriver {

    public static void main(String[] args) throws Exception {
        final String inputfile = "F:\\study\\Hadoop\\input\\outputFormat";
        final String outputfile = "F:\\study\\Hadoop\\output\\result3";

        Job job = Job.getInstance(new Configuration());

        job.setJarByClass(FilterDriver.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(NullWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(NullWritable.class);

        job.setMapperClass(FilterMapper.class);
        job.setReducerClass(FilterReducer.class);
        // 设置输出数据格式化 自定义输出格式
        job.setOutputFormatClass(FilterOutputFilter.class);
        FileInputFormat.addInputPath(job, new Path(inputfile));
        FileOutputFormat.setOutputPath(job, new Path(outputfile));

        boolean completion = job.waitForCompletion(true);

        System.exit(completion ? 1 : 0);
    }
}
